package com.mustafaiev.tair.cts.tapestry.select;

import java.util.ArrayList;
import java.util.List;

import org.apache.tapestry5.OptionGroupModel;
import org.apache.tapestry5.OptionModel;
import org.apache.tapestry5.SelectModel;
import org.apache.tapestry5.SelectModelVisitor;

import com.mustafaiev.tair.cts.facade.IPayerFacade;
import com.mustafaiev.tair.cts.tapestry.dto.PayerDTO;

public class PayerSelectModel implements SelectModel {

    private final IPayerFacade facade;

    public PayerSelectModel(final IPayerFacade facade) {
        this.facade = facade;
    }

    public List<OptionGroupModel> getOptionGroups() {
        return null;
    }

    public List<OptionModel> getOptions() {
        final List<PayerDTO> payerDtos = facade.retrievePayers();
        final List<OptionModel> optionModels = new ArrayList<OptionModel>();
        for (final PayerDTO payerDto : payerDtos) {
            optionModels.add(new PayerSelectOptionModel(payerDto));
        }
        return optionModels;
    }

    public void visit(final SelectModelVisitor visitor) {
        final List<OptionModel> optionModels = getOptions();

        if (optionModels != null) {
            for (final OptionModel optionModel : optionModels) {
                visitor.option(optionModel);
            }
        }
    }

}
